<template>
	<slot :controller="controller" :store="store" :model="model">
		<AppEXPViewLayout :class="classNames" :openType="openType">
			<template
				v-if="!noViewCaption && model.showCaption"
				#viewHeaderContentLeft
			>
				<div class="view-header__left__caption">
					<slot
						name="ViewCaption"
						:controller="controller"
						:store="store"
						:model="model"
					>
						<AppCaptionBar
							:caption="model.caption"
							:title="model.title"
							:capPSLanguageRes="model.capPSLanguageRes"
							:titlePSLanguageRes="model.titlePSLanguageRes"
							:openType="openType"
						></AppCaptionBar>
					</slot>
				</div>
			</template>
			<template #default>
				<AppSplit
					v-model="split"
					class="app-vc-expbar"
					mode="horizontal"
					@move-end="handleSplitChange(model, split)"
				>
					<template #left>
						<div class="app-vc-expbar__left">
							<slot
								name="Sys_organizationOrgDepartmentTreeExpViewtreeexpbarTreeExpBar"
								:controller="controller"
								:store="store"
								:model="model"
								:actions="{
									handleCtrlInit,
									handleCtrlAction,
									handleCtrlDestroy,
								}"
							>
								<Sys_organizationOrgDepartmentTreeExpViewtreeexpbarTreeExpBar
									:openView="store.openView"
									:newView="store.newView"
									name="treeexpbar"
									v-bind="model.ctrlParams.Sys_organizationtreeexpbar"
									:context="store.context"
									:viewParams="store.viewParams"
									:closeView="store.closeView"
									:pLoadingHelper="store.loadingHelper"
									:pViewCtx="store.viewCtx"
									@ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
									@ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
									@ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"
								>
								</Sys_organizationOrgDepartmentTreeExpViewtreeexpbarTreeExpBar>
							</slot>
						</div>
					</template>
					<template #right>
						<div class="app-vc-expbar__body">
							<component
								v-if="store.navParam && store.navParam.navViewName"
								openType="EMBED"
								:is="store.navParam.navViewName"
								:key="store.navParam.data.srfkey"
								:context="store.navParam.navData.context"
								:viewParams="store.navParam.navData.viewParams"
								:pLoadingHelper="store.loadingHelper"
								class="view-container2"
								@view-init="(name:string, data:any) => { handleCtrlInit(controller, name, data); }"
								@view-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data); }"
								@view-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data); }"
							>
							</component>
						</div>
					</template>
				</AppSplit>
			</template>
		</AppEXPViewLayout>
	</slot>
</template>
<script lang="ts" setup>
// 基于template/src/views/{{appModules}}/{{pages@DETREEEXPVIEW}}/{{spinalCase page.codeName}}-base.vue.hbs生成
import { AppEXPViewLayout } from '@components/layout/exp-view-layout';
import { AppSplit } from '@components/common/split';
import Sys_organizationOrgDepartmentTreeExpViewtreeexpbarTreeExpBar from '@widgets/sys-organization/org-department-tree-exp-viewtreeexpbar-tree-exp-bar/org-department-tree-exp-viewtreeexpbar-tree-exp-bar.vue';
import {
	useProps,
	useBasic,
	useAction,
	useController,
} from './sys-organization-org-department-tree-exp-view-hook';
import {
	IEvent,
	TreeExpViewActionType,
	ITreeExpViewAbility,
	ITreeExpViewStore,
	IParam,
} from '@/core';

// 输入参数
const props = defineProps(useProps());

//  导航分隔值
const split = ref(0.15);

// 基础数据
const {
	model,
	getClassNames,
	useNavParamsBind,
	useEventBind,
	handleQuickSearch,
	handleToolbarItemClick,
	handleComponentAction,
	handleCtrlAction,
	handleCtrlInit,
	handleCtrlDestroy,
	initSplit,
	handleSplitChange,
	handleQuickGroupValueChange,
} = useBasic(props);

const emit = defineEmits<{
	(
		event: 'view-action',
		name: string,
		action: TreeExpViewActionType,
		data: IParam[]
	): void;
	(event: 'view-init', name: string, data: ITreeExpViewAbility): void;
	(event: 'view-mounted', name: string, data: IParam): void;
	(event: 'view-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
	return getClassNames(props);
});

// 初始化控制器
const controller = useController(props, evt);

useNavParamsBind(controller, props);

const store: ITreeExpViewStore = controller.getStore();

onMounted(() => {
	controller.viewMounted();
	initSplit(getCurrentInstance());
});

onUnmounted(() => {
	controller.viewDestroy();
});
</script>
